import 'package:ccshop/entites/GoodsEntity.dart';
import 'package:flutter/material.dart';

class RightContentView extends StatelessWidget {
  List<GoodsEntity> goodsList = List();

  RightContentView() {
    GoodsEntity goodsEntity = GoodsEntity(
      "images/test/test01.png",
      "波兰土豆进口【次日达】",
      "波兰原装进口 新鲜自然 醇香浓厚",
      "￥39.99",
      "￥45.00",
    );
    goodsList.add(goodsEntity);

    goodsEntity = GoodsEntity(
      "images/test/test02.png",
      "瑞士大白菜进口【今日达】",
      "波兰原装进口 清甜可口",
      "￥9.99",
      "￥25.00",
    );
    goodsList.add(goodsEntity);

    goodsEntity = GoodsEntity(
      "images/test/test03.png",
      "粉西红柿（番茄）500g/斤",
      "口味甘甜 圆润可口 皮薄肉多",
      "￥11.99",
      "￥35.00",
    );
    goodsList.add(goodsEntity);

    goodsEntity = GoodsEntity(
      "images/test/test04.png",
      "新鲜的猪肉 500g/斤",
      "每日新鲜 赶快来买",
      "￥25.99",
      "￥35.05",
    );
    goodsList.add(goodsEntity);

    goodsEntity = GoodsEntity(
      "images/test/test05.png",
      "刚出的竹笋",
      "大熊猫和人都喜欢吃的",
      "￥29.99",
      "￥45.15",
    );
    goodsList.add(goodsEntity);

    goodsEntity = GoodsEntity(
      "images/test/test06.png",
      "超新鲜蒜台 450g/斤",
      "甘甜可口 蒜台炒肉",
      "￥9.99",
      "￥18.99",
    );
    goodsList.add(goodsEntity);
  }

  @override
  Widget build(BuildContext context) {
    return Expanded(
      child: ListView.separated(
          shrinkWrap: true,
          scrollDirection: Axis.vertical,
          itemCount: goodsList.length,
          separatorBuilder: (context, index) {
            return Divider(
              color: Colors.grey,
              indent: 10,
            );
          },
          itemBuilder: (context, index) {
            return Container(
              margin: EdgeInsets.only(left: 10, top: 20, bottom: 20),
              child: Row(
                children: [
                  Image.asset(
                    goodsList[index].goodsSrc,
                    width: 70,
                    height: 70,
                    fit: BoxFit.fill,
                  ),
                  Padding(padding: EdgeInsets.only(left: 10)),

                  // 右边布局
                  _CategoryRightView(goodsList[index]),
                ],
              ),
            );
          }),
    );
  }
}

class _CategoryRightView extends StatelessWidget {
  final GoodsEntity goodsEntity;

  _CategoryRightView(this.goodsEntity);

  @override
  Widget build(BuildContext context) {
    return Expanded(
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text(
            goodsEntity.goodsName,
            maxLines: 1,
            overflow: TextOverflow.ellipsis,
            style: TextStyle(
              fontSize: 16,
              fontWeight: FontWeight.bold,
            ),
          ),
          Text(
            goodsEntity.goodsDesc,
            style: TextStyle(fontSize: 10, color: Colors.grey),
          ),
          Padding(
              padding: EdgeInsets.only(
            top: 14,
          )),
          Row(
            children: [
              Container(
                width: 120,
                child: Row(
                  crossAxisAlignment: CrossAxisAlignment.end,
                  children: [
                    Text(
                      goodsEntity.goodsPrice,
                      style: TextStyle(
                        fontSize: 16,
                        color: Colors.red,
                      ),
                    ),
                    Text(
                      goodsEntity.goodsOldPrice,
                      style: TextStyle(
                          fontSize: 12,
                          color: Colors.black,
                          decoration: TextDecoration.lineThrough),
                    ),
                  ],
                ),
              ),
              Image.asset(
                "images/shop_item_cart.png",
                width: 26,
                height: 26,
              ),
            ],
          )
        ],
      ),
    );
  }
}
